home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UNIXTOOL / UNIXLIB37B / !UnixLib37_src_signal_c_signal < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  1.2 KB  |  47 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/signal,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: signal,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: signal,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* Written by Nick Burrett, 27 August 1996.  */
  18.  
  19. #include <errno.h>
  20. #include <signal.h>
  21.  
  22.  
  23. /* Set the handler for the signal 'sig' to handler, returning
  24.    the old handler, or SIG_ERR on error.  */
  25. sighandler_t
  26. signal (int sig, sighandler_t handler)
  27. {
  28.   struct sigaction act, oact;
  29.  
  30.   if (handler == SIG_ERR
  31.       || sig <= 0 || sig >= NSIG
  32.       || sig == SIGKILL || sig == SIGSTOP)
  33.     {
  34.       errno = EINVAL;
  35.       return SIG_ERR;
  36.     }
  37.  
  38.   act.sa_handler = handler;
  39.   if (sigemptyset (&act.sa_mask) < 0)
  40.     return SIG_ERR;
  41.   act.sa_flags = 0; /* sigismember (&_sigintr, sig) ? 0 : SA_RESTART; */
  42.   if (sigaction (sig, &act, &oact) < 0)
  43.     return SIG_ERR;
  44.  
  45.   return oact.sa_handler;
  46. }
  47.